package com.jmcgg.freesky.common.db;

import java.util.ArrayList;


/**
 * @author <b>Jacky Chou</b> (Copyright &#169; 2005~2010 AFSS [Amei's FreeSky
 *         Studio])
 * @version 1.2.0, 2008-02-23, Upgrade freesky.jar to 1.2.0 with Struts 2 <br>
 *          1.0.0, 2006-05-30, Initial Version
 */
public abstract class TableHelper {

	protected DBConnBean conn = null;

	protected String tableName = null;

	protected String opType = null;

	protected ArrayList<FieldValueBean> fvList = new ArrayList<FieldValueBean>();

	protected ArrayList<FieldValueBean> whereList = new ArrayList<FieldValueBean>();

	public TableHelper() {
	}

	public TableHelper(DBConnBean conn) {
		this.conn = conn;
	}

	public TableHelper(DBConnBean conn, String tableName) {
		this.conn = conn;
		this.tableName = tableName;
	}

	public TableHelper(DBConnBean conn, String tableName, String opType) {
		this.conn = conn;
		this.tableName = tableName;
		this.opType = opType;
	}

	public void ClearFVList() {
		this.fvList.clear();
	}

	public void ClearWhereList() {
		this.whereList.clear();
	}

	public void addFieldValue(String field, String value, String type) {
		this.fvList.add(new FieldValueBean(field, value, type));
	}

	public void addWhereValue(String field, String value, String type) {
		this.whereList.add(new FieldValueBean(field, value, type));
	}

	public void addFieldValue(FieldValueBean fvBean) {
		this.fvList.add(fvBean);
	}

	public void addWhereValue(FieldValueBean fvBean) {
		this.whereList.add(fvBean);
	}

	public abstract String getSQL();

	public abstract int execute();

	public DBConnBean getConn() {
		return conn;
	}

	public void setConn(DBConnBean conn) {
		this.conn = conn;
	}

	public String getOpType() {
		return opType;
	}

	public void setOpType(String opType) {
		this.opType = opType;
	}

	public String getTableName() {
		return tableName;
	}

	public void setTableName(String tableName) {
		this.tableName = tableName;
	}

	public void clear() {
		this.conn = null;
		this.fvList.clear();
		this.opType = null;
		this.tableName = null;
	}
}
